﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class LinkList : SkinnedGridView<LinkInfo>
    {
        /// <summary>
        /// 默认值从Url中读取参数SearchKey
        /// </summary>
        public string SearchKey
        {
            get { return SiteContext.Current.SearchKey; }
        }

        private int itemId = SiteContext.Current.CategoryId <= 0 ? SiteContext.Current.BaseNodeId : SiteContext.Current.CategoryId;
        public int ItemId
        {
            get { return itemId; }
            set { itemId = value; }
        }

        public StatusType? Status { get; set; }

        protected override IList<LinkInfo> GridViewDataSourceHandler(int pageIndex, int pageSize, out int totalRecord)
        {
            IEnumerable<LinkInfo> links=Links.GetLinks(SearchKey, ItemId);
            if(this.Status!=null)
                links=links.Where(info=>info.Status==this.Status);

            totalRecord = links.Count();

            return links.Skip((pageIndex-1) * pageSize).Take(pageSize).ToList();
        }

        protected override string DefaultSkinFilename
        {
            get { return "Link/LinkList.ascx"; }
        }
    }
}
